package cn.emailChat.ai.filterchain;

import cn.emailChat.ai.filterchain.util.MailWhitelist;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @Description 白名单过滤器
 * @Author susu
 * @Date 2025/8/20
 */
@Slf4j
@Component
@Order(1) // 优先级最高
@RequiredArgsConstructor
public class WhitelistHandler extends AbstractFilterHandler {

    private final MailWhitelist mailWhitelist;

    @Override
    protected boolean doFilter(String email) {
        try {
            return mailWhitelist.allowed(email);
        } catch (Exception ex) {
            // 记录异常日志，避免链路中断
            log.error("[WhitelistHandler] 白名单判定异常，email={}", email, ex);
            // 安全兜底策略：出现异常时默认拒绝，避免误放行
            return false;
        }
    }
}
